<?php

/**
 * UpdateAction class file.
 * 
 * @author Kien.Tran <kien.tran@logigear.com>
 * @copyright Copyright &copy; 2011 Andrius Marcinkevicius
 * @license Licensed under MIT license. http://ifdattic.com/MIT-license.txt
 * @version 2.1
 */

/**
 * LGActiveItemAction represents an action that Change the status of  a model using normal
 * view or EUpdateDialog extension.
 */
class LGUpdateAnItemAction extends LGAbstractAction {

    public $itemName = null;

    /**
     * Change the status of a model,
     * 	   if the status is published change to be unpublished
     * 	    else change to be published
     * @param type $models
     * @return \LGMessage
     */
    protected function defaultAction(&$models) {
	$isSuccessful = false;

	$model = $models[0];
	$model->scenario = 'update';

	
	$msgReturn = NULL;
	if (isset($_POST[$this->modelClass])) {
	    
	    $isSuccessful = $model->save();
	    if ($isSuccessful) {
		if ($this->itemName == null) {
		    $this->itemName = t('LBL_RECORD');
		}

		$msg = Yii::t('messages', 'MSG_INFO_SUCCESS', array('{0}' => $this->itemName, '{1}' => $actionName));
		$msgReturn = new LGMessage(MsgType::SUCCESS, $msg);
	    } else {
		$msgReturn = new LGMessage(MsgType::ERROR, $this->messages['error']);
	    }
	}

	return $msgReturn;
    }

}

?>